import React, { Component } from 'react';
import CustomBreadcrumb from '../../components/CustomBreadcrumb';
import SupplementCompanyForm from './components/SupplementCompany';
import { hashHistory } from 'react-router';
import { getUser, Update } from '../../auth'
import { CompanyService } from '../../services'

export default class SupplementCompany extends Component {
  static displayName = 'SupplementCompany';

  constructor(props) {
    super(props);
    let companyInfo = getUser()
    if(companyInfo.role !== 'COMPANY'){ 
      hashHistory.push('/')
    }
    this.state = {
      value : {
        ...companyInfo.account
      }
    };
  }

  onSubmit = async(data) =>{
    let account = await CompanyService.update(data);
    Update(account)
    hashHistory.push('/')
    return true
  }

  render() {
    const breadcrumb = [
      { text: '公司管理', link: null },
      { text: '补全公司信息', link: null },
    ];
    return (
      <div className="company-page">
        <CustomBreadcrumb dataSource={breadcrumb} />
        <SupplementCompanyForm value={this.state.value} onSubmit={this.onSubmit}/>
      </div>
    );
  }
}
